package com.yanqu.road.server.cmd.activity.climbtower;

import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ClimbTowerProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.climbtower.CrossClimbTowerMgr;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.C_CLIMB_TOWER_TOP_CLIMB, desc = "新幻境爬塔")
public class CrossClimbTowerTopClimbCmd extends CrossCommand {

    private long playerID;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        playerID = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ClimbTowerProto.ClimbTowerCrossTopClimbReqMsg reqMsg = ClimbTowerProto.ClimbTowerCrossTopClimbReqMsg.parseFrom(packet.getBytes());
        ret = CrossClimbTowerMgr.topCellClimb(reqMsg.getActivityId(), serverId, playerID, reqMsg.getAbility(), reqMsg.getPic(),
                reqMsg.getLv(), reqMsg.getMaxCellNum(), reqMsg.getCellNum(), reqMsg.getTargetUserId(), PlayerBasePb.parseBaseUserInfo(reqMsg.getUserBaseInfo()));
    }

    @Override
    public void sendData() {
        if (0 != ret) {
            ClimbTowerProto.ClimbTowerTopClimbRespMsg.Builder respMsg = CrossClimbTowerMgr.builderTopClimbRespMsg();
            respMsg.setRet(ret);
            MessageHelper.sendPacket(serverId, playerID, YanQuMessageUtils.buildMessage(Protocol.U_CLIMB_TOWER_TOP_CLIMB, respMsg));
        }
    }
}
